class Solution2 {
    public String longestDiverseString(int a, int b, int c) {
        CompareChar[] chars = new CompareChar[]{
                new CompareChar('a', a),
                new CompareChar('b', b),
                new CompareChar('c', c),
        };
        StringBuilder sb = new StringBuilder();
        while (true) {
            Arrays.sort(chars);
            if (sb.length() >= 2 &&
                    sb.charAt(sb.length() - 1) == chars[2].ch &&
                    sb.charAt(sb.length() - 2) == chars[2].ch) {
                if (chars[1].count-- > 0) {
                    sb.append(chars[1].ch);
                } else {
                    break;
                }

            } else {
                if (chars[2].count-- > 0) {
                    sb.append(chars[2].ch);
                } else {
                    break;
                }
            }
        }
        return sb.toString();
    }

    private class CompareChar implements Comparable {
        char ch;
        int count;

        public CompareChar(char ch, int count) {
            this.ch = ch;
            this.count = count;
        }

        @Override
        public int compareTo(Object o) {
            CompareChar compareChar = (CompareChar) o;
            return this.count - compareChar.count;
        }
    }
}